package com.zrwl.poscloud.xo.service.impl;
import com.zrwl.poscloud.base.entity.UserServiceOrderDetail;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zrwl.poscloud.base.enums.EStatus;
import com.zrwl.poscloud.base.superI.SuperServiceImpl;
import com.zrwl.poscloud.commons.utils.ResultUtil;
import com.zrwl.poscloud.commons.utils.StringUtils;
import com.zrwl.poscloud.xo.global.MessageConf;
import com.zrwl.poscloud.xo.global.SQLConf;
import com.zrwl.poscloud.xo.global.SysConf;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import com.zrwl.poscloud.xo.mapper.UserServiceOrderDetailMapper;
import com.zrwl.poscloud.xo.service.UserServiceOrderDetailService;
import com.zrwl.poscloud.xo.vo.UserServiceOrderDetailVO;

import javax.annotation.Resource;

/**
 * 订单记录 服务实现类
 *
 * @author 刘思童 AutoGenerate
 * @date 2023-05-29
 */
@Service
public class UserServiceOrderDetailServiceImpl extends SuperServiceImpl<UserServiceOrderDetailMapper,UserServiceOrderDetail> implements UserServiceOrderDetailService {

    @Autowired
    private UserServiceOrderDetailService userServiceOrderDetailService;
    @Resource
    private UserServiceOrderDetailMapper userServiceOrderDetailMapper;
    @Override
    public IPage<UserServiceOrderDetailVO> getPageList(UserServiceOrderDetailVO userServiceOrderDetailVO){
       Page<UserServiceOrderDetailVO> page = new Page<>();
       page.setCurrent(userServiceOrderDetailVO.getCurrentPage());
       page.setSize(userServiceOrderDetailVO.getPageSize());
       IPage<UserServiceOrderDetailVO> pageList = userServiceOrderDetailMapper.getPageList(page, userServiceOrderDetailVO);
       List<UserServiceOrderDetailVO> list = pageList.getRecords();
       pageList.setRecords(list);
       return pageList;
}
    @Override
    public List<UserServiceOrderDetail> getAllList(UserServiceOrderDetailVO userServiceOrderDetailVO){
        QueryWrapper<UserServiceOrderDetail> queryWrapper = new QueryWrapper<>();
        queryWrapper.ne(SQLConf.STATUS, EStatus.DISABLED);
        queryWrapper.orderByAsc(SQLConf.CREATE_TIME);
        List<UserServiceOrderDetail> list = userServiceOrderDetailService.list(queryWrapper);
        return list;
}
    @Override
    public String add(UserServiceOrderDetailVO userServiceOrderDetailVO){
        UserServiceOrderDetail entity = new UserServiceOrderDetail();
        BeanUtils.copyProperties(userServiceOrderDetailVO, entity, SysConf.STATUS);
        entity.insert();
        userServiceOrderDetailVO.setUid(entity.getUid());
        return ResultUtil.successWithMessage(MessageConf.INSERT_SUCCESS);}
    @Override
    public String edit(UserServiceOrderDetailVO userServiceOrderDetailVO){
        UserServiceOrderDetail entity = userServiceOrderDetailService.getById(userServiceOrderDetailVO.getUid());
        BeanUtils.copyProperties(userServiceOrderDetailVO, entity);
        entity.updateById();
        return ResultUtil.successWithMessage(MessageConf.UPDATE_SUCCESS);
}
    @Override
    public String delete(UserServiceOrderDetailVO userServiceOrderDetailVO){
        UserServiceOrderDetail entity = userServiceOrderDetailService.getById(userServiceOrderDetailVO.getUid());
        entity.setStatus(EStatus.DISABLED);
        entity.updateById();
        return ResultUtil.successWithMessage(MessageConf.UPDATE_SUCCESS);
}

    @Override
    public List<UserServiceOrderDetailVO> getOrderDetailByEmployeeUid(String employeeUid) {
        return userServiceOrderDetailMapper.getOrderDetailByEmployeeUid(employeeUid);
    }
}
